﻿using FluentNHibernate.Mapping;
using Journal.Domain.Models;

namespace Journal.NHibernate.Mappings
{
    public class UserMap : ClassMap<User>
    {
        public UserMap()
        {
            Table("[User]");
            Id(x => x.Id, "UserId").GeneratedBy.Identity();
            Map(m => m.Login).Length(50).Not.Nullable();
            Map(m => m.Password).Length(255).Not.Nullable();
            Map(m => m.PasswordSalt).Length(4001).Not.Nullable();
            Map(m => m.Email).Length(255).Not.Nullable();
            Map(m => m.IsDeleted);
            Map(m => m.IsDeactivated);
            HasManyToMany(m => m.Roles).Table("UserToRole").ParentKeyColumn("UserId").ChildKeyColumn("RoleId").Cascade.None();
            References(m => m.UserInfo, "UserInfoId").Cascade.All().Not.Nullable();
            HasManyToMany(m => m.Permissions).Table("PermissionToUser").ParentKeyColumn("UserId").ChildKeyColumn("PermissionId").Cascade.None();
        }
    }
}